<?php
namespace WXAPI\Logic;

use Think\Model\RelationModel;

/**
 * Token逻辑定义
 * Class TokenLogic
 * @package Home\Logic
 */
class TokenLogic extends RelationModel
{
    /**
     * @time 2023/08/09
     * @author lx
     * checkToken
     */
    public function checkToken($token,$user_id)
    {
//         // 获取当前时间戳
//         $currentTimestamp = time();
        
//         // 判断时间戳是否在 3 分钟内
//         if (($currentTimestamp - $token) <= (3 * 60)) {
//             return true;
//         } else {
//             return false;
//         }

//
//        $currentDateTime = strtotime(date('Y-m-d H:i').":00");
//
//        $currentDateTime1 = strtotime(date('Y-m-d H:i', strtotime('+5minute')).":00");
//
//        $days = date('mdH');
//        $currentDateTime = md5($days.$currentDateTime);
//        $currentDateTime1 = md5($days.$currentDateTime1);
//        if($currentDateTime == $token || $currentDateTime1 == $token){
//            return true;
//        }else{
//            return false;
//        }


        $currentDateTime1 = strtotime(date('Y-m-d H:i', strtotime('+1minute')).":00");
        $currentDateTime = strtotime(date('Y-m-d H:i').":00");
        $currentDateTime2 = strtotime(date('Y-m-d H:i', strtotime('-1minute')).":00");
        $currentDateTime3 = strtotime(date('Y-m-d H:i', strtotime('+2minute')).":00");
        $currentDateTime = md5(C('token_code').$currentDateTime);
        $currentDateTime1 = md5(C('token_code').$currentDateTime1);
        $currentDateTime2 = md5(C('token_code').$currentDateTime2);
        $currentDateTime3 = md5(C('token_code').$currentDateTime3);

     if($currentDateTime == $token ||$currentDateTime1 == $token || $currentDateTime2 == $token || $currentDateTime3 == $token){
            return true;
        }else{
            return false;
        }

    }
}